package dbmanagement;

import java.util.HashMap;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: [J0k3r]
 * Date: 07.12.2008
 * Time: 17:20:34
 */
public class FetchedTemplateParams implements Cloneable{
    private FetchedObjectTemplate template;
    private ArrayList < FetchedParam > params = new ArrayList < FetchedParam >();

    public FetchedTemplateParams(FetchedObjectTemplate template) {
        this.template = template;
    }

    public FetchedObjectTemplate getTemplate() {
        return template;
    }

    public void setTemplate(FetchedObjectTemplate template) {
        this.template = template;
    }

    public ArrayList < FetchedParam > getParams() {
        return params;
    }

    public void setParams(ArrayList < FetchedParam > params) {
        this.params = params;
    }

    public FetchedParam getParam(String paramName) {
        for (FetchedParam param : params) {
            if (param.getName().equals(paramName))
                return param;
        }
        return null;
    }

    public boolean containsParam(String paramName) {
        for (FetchedParam param : params) {
            if (param.getName().equals(paramName))
                return true;
        }
        return false;
    }

    public void addParam(FetchedParam param) {
        for (FetchedParam fetchedParam : params)
            if (fetchedParam.getName().equals(param.getName())) {
                params.remove(fetchedParam);
                break;
            }
        params.add(param);
    }

    protected Object clone() throws
            CloneNotSupportedException {
        FetchedTemplateParams ftp = new FetchedTemplateParams((FetchedObjectTemplate) template.clone());
        ArrayList < FetchedParam > params = new ArrayList<FetchedParam>();
        for (FetchedParam it : this.params)
            params.add((FetchedParam) it.clone());
        ftp.setParams(params);
        return ftp;
    }
}
